package com.ktjiaoyu.crm.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktjiaoyu.crm.mapper.UserMapper;
import com.ktjiaoyu.crm.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(String usrName, String usrPassword) {
        //条件构造器
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("usr_name",usrName);
        queryWrapper.eq("usr_password",usrPassword);
        return userMapper.selectOne(queryWrapper);
    }

    @Override
    public Page<User> getUsersByPages(Page<User> page, Wrapper<User> queryWrapper) {

        return page.setRecords(this.baseMapper.selectUserPages(page,queryWrapper));
    }

    @Override
    public List<User> selectUserPages(Page<User> page, Wrapper<User> queryWrapper) {

        return userMapper.selectUserPages(page,queryWrapper);
    }

    @Override
    public boolean addUsers(User user) {

        return userMapper.addUsers(user);
    }
}
